package com.youdo.service;

import static com.youdo.uvccamera.CameraConstants.*;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * api传参
 *
 * @author ljb
 * @date 2025.06.30
 * @email 568838953@qq.com
 */
public class CameraAction implements Parcelable {

    private int type;
    private Bundle data;

    public CameraAction(int actionType) {
        this.type = actionType;
        this.data = null;
    }

    public CameraAction(int actionType, Bundle actionData) {
        this.type = actionType;
        this.data = actionData;
    }

    public CameraAction(int actionType, boolean value) {
        this.type = actionType;
        this.data = new Bundle();
        data.putBoolean(ACTION_KEY, value);
    }

    public CameraAction(int actionType, int value) {
        this.type = actionType;
        this.data = new Bundle();
        data.putInt(ACTION_KEY, value);
    }

    public CameraAction(int actionType, String value) {
        this.type = actionType;
        this.data = new Bundle();
        data.putString(ACTION_KEY, value);
    }

    public String getTypeStr() {
        switch (type) {
            case ACTION_SET_DEBUG_MODE:
                return "set_debug_mode";
            case ACTION_SET_SEGMENT_PERIOD:
                return "action_set_segment_period";
            case ACTION_SET_FRAME_CALLBACK:
                return "action_set_frame_callback";
            case ACTION_SET_SAVE_MODE:
                return "action_set_save_mode";
            case ACTION_SET_SAVE_PATH:
                return "action_set_save_path";
            case ACTION_GET_SAVE_MOVIES_PATH:
                return "action_get_save_movies_path";
            case ACTION_GET_SAVE_PICTURE_PATH:
                return "action_get_save_picture_path";
            case ACTION_SET_AUDIO_RECORD:
                return "action_set_audio_record";
            default:
                return "set_unknown";
        }
    }

    public boolean getBoolean() {
        return data.getBoolean(ACTION_KEY);
    }

    public int getInt() {
        return data.getInt(ACTION_KEY);
    }

    public String getString() {
        return data.getString(ACTION_KEY);
    }

    public int getType() {
        return type;
    }

    public Bundle getData() {
        return data;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.type);
        dest.writeBundle(data);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readInt();
        data = source.readBundle();
    }

    private CameraAction(Parcel in) {
        readFromParcel(in);
    }

    public static final Creator<CameraAction> CREATOR = new Creator<CameraAction>() {
        public CameraAction createFromParcel(Parcel source) {
            return new CameraAction(source);
        }

        public CameraAction[] newArray(int size) {
            return new CameraAction[size];
        }
    };
}
